package com.cty.service.impl;

import com.cty.mapper.UserMapper;
import com.cty.pojo.User;
import com.cty.service.UserService;
import com.cty.util.MyBatisUtil;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Auther: cty
 * @Date: 2020/2/29 20:41
 * @Description:
 * @version: 1.0
 */
public class UserServiceImpl implements UserService {
    // 获取日志对象
    Logger log = Logger.getLogger(UserServiceImpl.class);

    @Override
    public int insService(User user) throws IOException {
        // 获取SqlSession
        SqlSession session = MyBatisUtil.getSession();
        // 获取绑定接口实现类
        UserMapper userMapper = session.getMapper(UserMapper.class);
        // 执行方法
        if(null!=user){
            log.debug(user.getUname()+"发起插入数据请求");
        }else {
            log.debug("发起插入数据请求");
        }
        int index = userMapper.ins(user);  // 调用方法，插入数据
        if(index > 0){
            log.debug("插入数据成功");
        }else{
            log.debug("插入数据失败");
        }

        return index;
    }
}
